// pages/personcenter/personcenter.js
import {ApiRootUrl,apiList} from '../../../config/index.js'
import {IMG_PATH} from '../../../config/index.js'
import {
  request
} from "../../../utils/util.js"
import Toast from '../../../@vant/weapp/toast/toast';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isTongguo:true,
    IMG_PATH:IMG_PATH,
    id:0,
    tongzhimessage:"",
    noticeType:"",
    tongzhiShow:false,
    familyinfo:{
      name:'张三',
      sex:'男',
      relation:'父亲',
      phone:'13912206480'
    },
    statusBarHeight: '',
    isShowPending:false,
    employeeInfo:{},
    ids:"",
    workList:[{
      starttime:'',
      endtime:'',
      name:'',
      gangwei:'',
      reason:'',
      isconfirm:''
    }],
    xueliList:[{
      starttime:'',
      endtime:'',
      name:'',
      zhaunye:'',
      xueli:'',
      remark:''
    }],
    familyList:[{
      name:'',
      relation:'',
      birthday:'',
      organization:'',
      job:'',
      phone:''
    }],
    baseinfo:{
     
    },
    companyinfo:{
      name:'史密斯有限公司',
      position:'空港新区',
      hrname:'蒋恺',
      hrphone:'12939393939',
      time:'2020-12-20'
    },
    susheinfo:{
      position:'空港新区',
      sushename:'宿舍1号',
      room:'404',
      chuanwei:'3',
      suguanname:' 李四',
      suguanphone:'12939393939',
      time:'020-12-20'
    },
    tabList:[{
      title:'基本信息',
    },{
      title:'家庭信息',
    },{
      title:'学历信息',
    },{
      title:'工作经历',
    },{
      title:'紧急联系人',
    }],
    active:0
  },
  backClick(){
    wx.navigateBack();
  },
  refendallClick(e){
    let type = Number(e.currentTarget.dataset.type) // 0 通过  1 待定 2 未通过
    this.setData({
      noticeType:type,
      tongzhiShow:true
    })
    this.checkJob(this.data.ids,this.data.noticeType)
  },
  checkJob(id,status,message){
    let params = {
      idList:[id],
      jobStatus:status,
      remark:message
    }
    Toast.loading({
      message: '处理中...',
      mask: true,
      duration: 0,
      forbidClick: true,
    });
    request(apiList.checkJob,params).then((res) => {
     console.log("请求结果=====>",res)
      wx.navigateBack({
        delta: 1
      })
      Toast.clear();
    }).catch((err) => {
      console.log("err==>",err)
      Toast.clear();
      Toast({
        duration: 3000,
        forbidClick: true,
        type: 'fail',
        message: err.message,
      });
    })
  },
  onChange(event){
    this.setData({
      active:event.detail.index
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
    let id = options.id;
    let ids = options.ids;
    if(options.isTongguo&&options.isTongguo==1){
      this.setData({
        isTongguo:false
      })
    }
    let requestType = options.requestType;
    let type = false
    if(options.type == "true"){
      type = true
    }else{
      type = false
    }
    this.setData({
      statusBarHeight:wx.getSystemInfoSync()['statusBarHeight'],
      isShowMiddle:type,
      id:id,
      ids:ids
    })
    this.getBasciInfo(id,requestType)
  },
  getBasciInfo(id,type){
    // Toast.loading({
    //   message: '加载中...',
    //   mask: true,
    //   duration: 0,
    //   forbidClick: true,
    // });
    wx.showLoading({
      title: '加载中...',
    })
    request(apiList.personalDetail+"/"+id+"/"+type,{},"GET").then(res =>{
      if(res.data.workList&&res.data.workList.length){
        this.setData({
          workList:res.data.workList,
        })
      }
      if(res.data.educationList&&res.data.educationList.length){
        this.setData({
          xueliList:res.data.educationList,
        })
      }
      if(res.data.familyList&&res.data.familyList.length){
        this.setData({
          familyList:res.data.familyList,
        })
      }
      this.setData({
        baseinfo:res.data.employeeDetails,
        employeeInfo:res.data.employeeInfo,
        // xueliList:res.data.educationList,
        // familyList:res.data.familyList,
        familyinfo:res.data.contactList == null ? {}:res.data.contactList[0]
      })
      wx.hideLoading()
    }).catch(err =>{
      // Toast.clear();
      wx.hideLoading()
      Toast({
        duration: 3000,
        forbidClick: true,
        type: 'fail',
        message: err.message,
      });
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})